<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改宠物信息')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-pet-edit" th:object="${pet}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">宠物名称：</label>
                    <div class="col-sm-8">
                        <input name="name" th:field="*{name}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">宠物品种：</label>
                    <div class="col-sm-8">
                        <select name="categoryId" id="categoryId" class="form-control" required>
                            <!-- 商品选项将通过 JavaScript 动态填充 -->
                            <option th:each="category:${categoryList}" th:value="${category.id}" th:text="${category.categoryName}" th:selected="${pet.categoryId == category.id}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">健康状况：</label>
                    <div class="col-sm-8">
                        <input name="healthStatus" th:field="*{healthStatus}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">宠物年龄：</label>
                    <div class="col-sm-8">
                        <input name="age" th:field="*{age}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">宠物性别：</label>
                    <div class="col-sm-8">
                        <select name="gender" id="gender" class="form-control" required>
                            <!-- 商品选项将通过 JavaScript 动态填充 -->
                            <option th:each="sex:${sexs}" th:value="${sex.sexKey}" th:text="${sex.sexValue}" th:selected="${pet.gender == sex.sexKey}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">宠物价格：</label>
                    <div class="col-sm-8">
                        <input name="price" th:field="*{price}" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">图片：</label>
                    <!--                 onclick="$.triggerFileInput()"-->
                    <div class="UploadImg">  <!-- 为整个区域添加点击事件 -->
                        <div class="imgList" id="imgList">
                            <!-- 这里用于显示已上传的图片或加载状态 -->
                            <img th:if="${pet.imgUrl}" th:src="${pet.imgUrl}" width="100" height="100" border-radius="10" border="1px solid #d9d9d9" />
                        </div>
                    </div>
                    <input type="file" id="fileInput" style="display: none;"/>
                    <!-- 隐藏的文件输入元素，并绑定 onchange 事件 -->
                    <input name="imgUrl" id="imgUrl" th:field="*{imgUrl}" class="form-control" type="hidden">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/pet";
        var uploadUrl = ctx + "common/upload";
        $(document).ready(function() {
            $("#form-pet-edit").validate({
                focusCleanup: true

            });

            // 当页面加载完成时，执行以下代码
            $.fileUpload.init();
        });
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-pet-edit').serialize());
            }
        }
    </script>
</body>
</html>